import { configureStore } from '@reduxjs/toolkit';
import { combineReducers } from 'redux';
import logger from 'redux-logger';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import globalReducer from './slice/global';
import messageReducer from './slice/message';
import userReducer from './slice/user';

const reducers = combineReducers({
  message: messageReducer,
  global: globalReducer,
  user: userReducer,
});

const persistConfig = {
  key: 'bsf_local',
  storage,
  // 黑名单 不缓存的
  // blacklist: ['page404'],
};

const persistedReducer = persistReducer(persistConfig, reducers);

const store = configureStore({
  reducer: persistedReducer,
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export default store;
